package com.league.zjxn.jetpack.vmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.league.zjxn.app.SPSConstance
import com.league.zjxn.base.BaseViewModel
import com.league.zjxn.entity.*
import com.league.zjxn.jetpack.repository.HomeRepository
import com.league.zjxn.jetpack.repository.UserRepository
import com.module.lemlin.http.HttpResponseBody
import com.module.lemlin.http.HttpResponseData
import com.module.lemlin.http.SubscribeViewModel


class UserViewModel(application: Application) : BaseViewModel(application) {

    private val mUserRepository: UserRepository = UserRepository()

    val contactUsLiveData = MutableLiveData<HttpResponseBody<ContactUsResponse>>()
    fun userContactUs() {
        setRxLifeScope(SubscribeViewModel(contactUsLiveData)) {
            mUserRepository.userContactUs()
        }
    }

    val followStatisticsLiveData = MutableLiveData<HttpResponseBody<FollowStatisticsResponse>>()
    fun userFollowStatistics() {
        setRxLifeScope(SubscribeViewModel(followStatisticsLiveData)) {
            mUserRepository.userFollowStatistics()
        }
    }

    val userInfoLiveData = MutableLiveData<HttpResponseBody<UserInfoResponse>>()
    fun userInfo() {
        setRxLifeScope(object : SubscribeViewModel<UserInfoResponse>(userInfoLiveData) {
            override fun onSuccess(resp: UserInfoResponse) {
                super.onSuccess(resp.apply { SPSConstance.userInfo = data })
            }
        }) {
            mUserRepository.userInfo()
        }
    }

    val followEnterpriseLiveData = MutableLiveData<HttpResponseBody<FollowEnterpriseResponse>>()
    fun userFollowEnterprise(type: String) {
        setRxLifeScope(SubscribeViewModel(followEnterpriseLiveData)) {
            mUserRepository.userFollowEnterprise(type = type, page = "1", limit = "50")
        }
    }

    val followProjectLiveData = MutableLiveData<HttpResponseBody<FollowProjectResponse>>()
    fun userFollowProject(type: String) {
        setRxLifeScope(SubscribeViewModel(followProjectLiveData)) {
            mUserRepository.userFollowProject(type = type, page = "1", limit = "50")
        }
    }


    val projectApplyLiveData = MutableLiveData<HttpResponseBody<ProjectApplyResponse>>()
    fun userProjectApply(type: String) {
        setRxLifeScope(SubscribeViewModel(projectApplyLiveData)) {
            mUserRepository.userProjectApply(type = type, page = "1", limit = "100")
        }
    }

    val enterpriseApproveLiveData = MutableLiveData<HttpResponseBody<EnterpriseApproveResponse>>()
    fun userEnterpriseApprove(status:String?=null) {
        setRxLifeScope(SubscribeViewModel(enterpriseApproveLiveData)) {
            mUserRepository.userEnterpriseApprove(status,page = "1", limit = "100")
        }
    }

    val approveFlowLiveData = MutableLiveData<HttpResponseBody<ApproveFlowResponse>>()
    fun userApproveFlow(id: String) {
        setRxLifeScope(SubscribeViewModel(approveFlowLiveData)) {
            mUserRepository.userApproveFlow(id)
        }
    }

    val leagueApproveLiveData = MutableLiveData<HttpResponseBody<HttpResponseData>>()
    fun userLeagueApprove(
        name: String, person: String, contract: String, industry_id: String?=null,
        province_id: String? = null, city_id: String? = null, content: String
    ) {
        setRxLifeScope(SubscribeViewModel(leagueApproveLiveData)) {
            mUserRepository.userLeagueApprove(
                name, person, contract, industry_id, province_id, city_id, content
            )
        }
    }

    val industryListLiveData = MutableLiveData<HttpResponseBody<IndustryListResponse>>()
    fun userIndustryList() {
        setRxLifeScope(SubscribeViewModel(industryListLiveData)) {
            mUserRepository.userIndustryList()
        }
    }

    val regionListLiveData = MutableLiveData<HttpResponseBody<RegionListResponse>>()
    fun userRegionList() {
        setRxLifeScope(SubscribeViewModel(regionListLiveData)) {
            mUserRepository.userRegionList()
        }
    }
}